package zw_901_1000.zw_917_仅仅反转字母;

class Solution {
    public static void main(String[] args) {
        String s = "7_28]";
        String letters = reverseOnlyLetters(s);
        System.out.println(letters);
    }

    public static String reverseOnlyLetters(String s) {
        char[] cs = s.toCharArray();
        int left = 0, right = cs.length - 1;
        while (left < right) {
            while (left < right && !Character.isLetter(cs[left])) {
                left++;
            }
            while (right > 0 && !Character.isLetter(cs[right])) {
                right--;
            }
            if (!(left < right)) break;
            char c = cs[left];
            cs[left] = cs[right];
            cs[right] = c;
            left++;
            right--;
        }
        return String.valueOf(cs);
    }
}
